package com.neu.questionnaire_system.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.neu.questionnaire_system.beans.ResponseEntity;
import com.neu.questionnaire_system.entity.Tenant;
import com.neu.questionnaire_system.mapper.TenantMapper;
import com.neu.questionnaire_system.service.TenantService;
import com.neu.questionnaire_system.service.impl.TenantServiceImpl;
import org.apache.commons.mail.EmailException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xingle
 * @since 2022-10-31
 */
@RestController
@RequestMapping("/tenant")
@CrossOrigin
public class TenantController {

    @Autowired
    private TenantServiceImpl tenantService;


    @RequestMapping("/insertTenant")
    public ResponseEntity insertTenant(String tenantName, String id, String password, String phone){
        return tenantService.insertTenant(tenantName,id,password,phone);
    }

    @RequestMapping("/showTenant")
    public ResponseEntity showTenant(){
        return tenantService.showTenant();
    }

    @RequestMapping("/deleteTenant")
    public ResponseEntity deleteTenant(String tid){
        return tenantService.deleteTenant(tid);
    }

    @RequestMapping("/findTenant")
    public ResponseEntity findTenantById(String tid){
        return tenantService.findTenantById(tid);
    }

    @RequestMapping("/updateTenant")
    public ResponseEntity updateTenantById(String tid,String tenantName,String password,String phone){
        return tenantService.updateTenantById(tid,tenantName,password,phone);
    }

    @RequestMapping("/login")
    public ResponseEntity login(String tenantName,String password){
        return tenantService.login(tenantName,password);
    }
    @RequestMapping("/sendTenantEmail")
    public ResponseEntity sendTenantEmail(@RequestBody Map<String,Object> map) throws EmailException {return tenantService.sendTenantEmail(map);}
    @RequestMapping("/findTenantByName")
    public ResponseEntity findTenantByName(String tenantName){
        return tenantService.findTenantByName(tenantName);
    }

    @RequestMapping("/updateTenantByName")
    public ResponseEntity updateTenantByName(String oldTenantName, String newTenantName, String password, String phone){
        return tenantService.updateTenantByName(oldTenantName,newTenantName,password,phone);
    }

    @RequestMapping("/deleteTenantByName")
    public ResponseEntity deleteTenantByName(String tenantName){
        return tenantService.deleteTenantByName(tenantName);
    }



    @RequestMapping("/tenantStatistic")
    public ResponseEntity tenantStatistic(){
        return tenantService.TenantStatistic();
    }


}
